package com.paiai.lslease.dao.appuser;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.paiai.lslease.model.AppSysUserInfo;

import java.sql.SQLException;
import java.util.List;

public class AppSysUserInfoDAOImpl implements AppSysUserInfoDAO {

    private SqlMapClient sqlMapClient;

    public AppSysUserInfoDAOImpl(SqlMapClient sqlMapClient) {
        super();
        this.sqlMapClient = sqlMapClient;
    }

    public AppSysUserInfo getAppSysUserInfoById(int userId) throws SQLException {
        List<AppSysUserInfo> appSysUserInfoList = sqlMapClient.queryForList("app_sys_user_info.selectUserInfoById", userId);
        return appSysUserInfoList == null || appSysUserInfoList.size() == 0 ? null : appSysUserInfoList.get(0);
    }

    public AppSysUserInfo getAppSysUserInfoByMobile(String mobile) throws SQLException {
        List<AppSysUserInfo> appSysUserInfoList = sqlMapClient.queryForList("app_sys_user_info.selectUserInfoByMobile", mobile);
        return appSysUserInfoList == null || appSysUserInfoList.size() == 0 ? null : appSysUserInfoList.get(0);
    }

    public AppSysUserInfo getAppSysUserInfoByWechatOpenId(String wechatOpenId) throws SQLException {
        List<AppSysUserInfo> appSysUserInfoList = sqlMapClient.queryForList("app_sys_user_info.selectUserInfoByWechatOpenId", wechatOpenId);
        return appSysUserInfoList == null || appSysUserInfoList.size() == 0 ? null : appSysUserInfoList.get(0);
    }

    @Override
    public int selectNeweastAppSysUserId() throws SQLException {
        return (Integer) sqlMapClient.queryForObject("app_sys_user_info.selectNeweastSysUserId");
    }
}
